import com.atguigu.bigdata.gmall.realtime.bean.KeywordBean;

import java.lang.reflect.Field;

/**
 * @Author lzc
 * @Date 2022/10/14 15:10
 */
public class Demo10 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException, InstantiationException, IllegalAccessException {
        // 如何获取一个 class
        // Class.forName()   类名.class   对象.getClass()
    
//        Class<?> tClass = Class.forName("com.atguigu.bigdata.gmall.realtime.bean.KeywordBean");
        Class<KeywordBean> tClass = KeywordBean.class;
        // 获取所有 public 的属性
//        Field[] fields = tClass.getFields();
        /*Field[] fields = tClass.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field.getName());
        }*/
    
       /* KeywordBean bean = tClass.newInstance();
        Field stt = tClass.getDeclaredField("stt");
        stt.setAccessible(true); // 给私有成员设置访问权限
        stt.set(bean, "abc");  // bean.stt="abc"
    
        System.out.println(bean);
    
        System.out.println(stt.get(bean));*/
    
        Field[] fields = tClass.getDeclaredFields();
       /* String r = Arrays.stream(fields)
            .map(Field::getName)
            .collect(Collectors.joining(","));
        System.out.println(r);*/
    
        String msg = "";
        for (Field field : fields) {
            msg += field.getName() + ",";
        }
        msg = msg.substring(0, msg.length() -1 );
        System.out.println(msg);
    
    
    }
}
